home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / mpimagelib.lha / si / ConvertMPImage.c next >
C/C++ Source or Header  |  1997-02-16  |  15KB  |  528 lines

  1. /* Convert and display images */
  2.  
  3. /* mark@topic.demon.co.uk */
  4. /* mpaddock@cix.compulink.co.uk */
  5.  
  6. /* This is freely distributable */
  7.  
  8. #include <proto/exec.h>
  9. #include <proto/dos.h>
  10. #include <proto/intuition.h>
  11. #include <proto/graphics.h>
  12. #include <proto/utility.h>
  13. #include <proto/locale.h>
  14.  
  15. #include <dos/dos.h>
  16.  
  17. #include <math.h>
  18.  
  19. /* EGS Stuff    */
  20. #include <egs/clib/egs_protos.h>
  21. #include <egs/pragmas/egs_pragmas.h>
  22.  
  23. #include <egs/clib/egsintui_protos.h>
  24. #include <egs/pragmas/egsintui_pragmas.h>
  25.  
  26. #include <egs/clib/egsgfx_protos.h>
  27. #include <egs/pragmas/egsgfx_pragmas.h>
  28.  
  29. #include <egs/egsintui.h>
  30.  
  31. extern struct Library *EGSIntuiBase    = NULL;
  32. extern struct Library *EGSGfxBase    = NULL;
  33. extern struct Library *EGSBase        = NULL;
  34.  
  35. #include <libraries/MPImage.h>
  36. #include <pragmas/MPImage_pragmas.h>
  37. #include <clib/MPImage_protos.h>
  38. #include <dos.h>
  39. #include <string.h>
  40. #include <dos/rdargs.h>
  41.  
  42. #define TEMPLATE "FROM/A,X/N/K,Y/N/K,MINX/N/K,MINY/N/K,MAXX/N/K,MAXY/N/K,PUBSCREEN/K,EGS/S,NOREMAP/S,CLONE/S,TO/K,FORMAT/K,FORCEGREY/S,PALETTE/K,COLOURS/K/N,12BIT/S,LINEAR/S,WHITE0/S,MODENAME/K,NOPROGRESS/S,GUI/S"
  43.  
  44. #define OPT_FILE            0
  45. #define OPT_X                1
  46. #define OPT_Y                2
  47. #define OPT_MINX            3
  48. #define OPT_MINY            4
  49. #define OPT_MAXX            5
  50. #define OPT_MAXY            6
  51. #define OPT_SCREEN        7
  52. #define OPT_EGS            8
  53. #define OPT_NOREMAP        9
  54. #define OPT_CLONE            10
  55. #define OPT_TO                11
  56. #define OPT_FORMAT        12
  57. #define OPT_FORCEGREY    13
  58. #define OPT_PALETTE        14
  59. #define OPT_COLOURS        15
  60. #define OPT_12BIT            16
  61. #define OPT_LINEAR        17
  62. #define OPT_WHITE0        18
  63. #define OPT_MODENAME        19
  64. #define OPT_PROGRESS        20
  65. #define OPT_GUI            21
  66.  
  67. #define OPT_COUNT            22
  68.  
  69. extern long __oslibversion=39;
  70.  
  71. extern long __stack = 16000;
  72.  
  73. struct Library *MPImageBase;
  74.  
  75. const char Version[]="$VER: ConvertMPImage 7.2 (16.2.97)";
  76.  
  77. UBYTE NewMap256[256] = {  1,   2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
  78.                                   16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  79.                                   32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  80.                                   48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  81.                                   64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  82.                                   80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  83.                                   96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
  84.                                  112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
  85.                                  128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
  86.                                  144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
  87.                                  160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
  88.                                  176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
  89.                                  192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
  90.                                  208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
  91.                                  224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
  92.                                  240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,  0
  93.                                 };
  94. UBYTE NewMap16[16] = {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,  0
  95.                             };
  96.  
  97. extern struct Catalog *Catalog=NULL;
  98.  
  99. #define CATCOMP_BLOCK
  100. #define CATCOMP_NUMBERS
  101. #include "Cmessages.h"
  102.  
  103. char
  104. *GetMessage(UWORD message) {
  105.     LONG   *l;
  106.     UWORD  *w;
  107.     STRPTR  builtIn;
  108.  
  109.    l = (LONG *)CatCompBlock;
  110.  
  111.     while (*l != message)  {
  112.         w = (UWORD *)((ULONG)l + 4);
  113.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  114.     }
  115.     builtIn = (STRPTR)((ULONG)l + 6);
  116.     return(GetCatalogStr(Catalog,message,builtIn));
  117. }
  118.  
  119. int
  120. main(int argc,char **argv) {
  121.     BOOL FromWB = FALSE;
  122.     struct RDArgs *rdargs = NULL;
  123.     LONG opts[OPT_COUNT] = {
  124.         0
  125.     };
  126.     int resx = RETURN_OK;
  127.     struct EasyStruct es = {
  128.         sizeof(struct EasyStruct),
  129.         0,
  130.         "ConvertMPImage",
  131.         NULL,
  132.         NULL
  133.     };
  134.     struct MPImage *MPi;
  135.     struct Screen *screen;
  136.     struct Window *win;
  137.     struct IntuiMessage *msg;
  138.     BOOL done;
  139.     struct EI_NewWindow    EGS_NewWindow = {0};    // EGS New window
  140.     struct EI_Window        *EGS_Win;                // EGS Window
  141.     struct EI_EIntuiMsg     *EGSmsg;                    // Message from the EGS windows
  142.     ULONG newx=0,newy=0;
  143.  
  144.     Catalog = OpenCatalog(NULL,
  145.                                   "mp/convertmpimage.catalog",
  146.                                   TAG_END);
  147.     es.es_GadgetFormat = GetMessage(MSG_OK);
  148.     if (argc == 0) {
  149.         argc = _WBArgc;
  150.         argv = _WBArgv;
  151.         FromWB = TRUE;
  152.         if (argc < 2) {
  153.             es.es_TextFormat = GetMessage(MSG_DOUBLE);
  154.             EasyRequestArgs(NULL,&es,NULL,NULL);
  155.             CloseCatalog(Catalog);
  156.             return RETURN_WARN;
  157.         }
  158.         opts[OPT_FILE] = (LONG)argv[1];
  159.         
  160.     }
  161.     else {
  162.         if (!(rdargs = ReadArgs((char *)TEMPLATE, opts, NULL))) {
  163.             PrintFault(IoErr(), NULL);
  164.             CloseCatalog(Catalog);
  165.             return RETURN_ERROR;
  166.         }
  167.         if (opts[OPT_GUI]) {
  168.             FromWB=TRUE;
  169.         }
  170.     }
  171.     if (MPImageBase = OpenLibrary("MPImage.library",6)) {
  172.         SetMPImageScreen((char *)opts[OPT_SCREEN],opts[OPT_PROGRESS]?0:MPIF_PROGRESS);
  173.         if (opts[OPT_TO] || opts[OPT_FORMAT]) {
  174.             if (MPi=LoadMPImage((UBYTE *)opts[OPT_FILE],NULL,
  175.                                         (opts[OPT_FORCEGREY] ? MPIF_FORCEGREY : MPIF_GREY) |
  176.                                         (opts[OPT_LINEAR] ? MPIF_LINEARGREY : 0))) {
  177.                 if (opts[OPT_MINX]) {
  178.                     if (MPi->Width < *((ULONG *)opts[OPT_MINX])) {
  179.                         newx = *((ULONG *)opts[OPT_MINX]);
  180.                     }
  181.                 }
  182.                 if (opts[OPT_MAXX]) {
  183.                     if (MPi->Width > *((ULONG *)opts[OPT_MAXX])) {
  184.                         newx = *((ULONG *)opts[OPT_MAXX]);
  185.                     }
  186.                 }
  187.                 if (!opts[OPT_MINX] && !opts[OPT_MAXX]) {
  188.                     if (opts[OPT_X]) {
  189.                         newx = *((ULONG *)opts[OPT_X]);
  190.                     }
  191.                 }
  192.                 if (opts[OPT_MINY]) {
  193.                     if (MPi->Height < *((ULONG *)opts[OPT_MINY])) {
  194.                         newy = *((ULONG *)opts[OPT_MINY]);
  195.                     }
  196.                 }
  197.                 if (opts[OPT_MAXY]) {
  198.                     if (MPi->Height > *((ULONG *)opts[OPT_MAXY])) {
  199.                         newy = *((ULONG *)opts[OPT_MAXY]);
  200.                     }
  201.                 }
  202.                 if (!opts[OPT_MINY] && !opts[OPT_MAXY]) {
  203.                     if (opts[OPT_Y]) {
  204.                         newy = *((ULONG *)opts[OPT_Y]);
  205.                     }
  206.                 }
  207.                 if (newx || newy) {
  208.                     if (!newx) {
  209.                         newx = MPi->Width;
  210.                     }
  211.                     if (!newy) {
  212.                         newy = MPi->Height;
  213.                     }
  214.                     if (!RescaleMPImage(MPi,newx,newy)) {
  215.                         if (FromWB) {
  216.                             es.es_TextFormat = MPImageErrorMessage();
  217.                             EasyRequestArgs(NULL,&es,NULL,NULL);
  218.                         }
  219.                         else {
  220.                             Printf(MPImageErrorMessage());
  221.                             Printf("\n");
  222.                         }
  223.                         resx = RETURN_FAIL;
  224.                     }
  225.                 }
  226.                 if (!resx) {
  227.                     UBYTE *GreyMap = NULL;
  228.                     if (opts[OPT_WHITE0]) {
  229.                         if (!opts[OPT_FORMAT] || !stricmp((UBYTE *)opts[OPT_FORMAT],MPI_BW16)) {
  230.                             GreyMap = NewMap16;
  231.                         }
  232.                         else {
  233.                             if (!stricmp((UBYTE *)opts[OPT_FORMAT],MPI_BW256)) {
  234.                                 GreyMap = NewMap256;
  235.                             }
  236.                         }
  237.                     }
  238.                     if (!SaveMPImage((UBYTE *)opts[OPT_TO],
  239.                                         MPi->Red, MPi->Green, MPi->Blue,
  240.                                         MPi->Width, MPi->Height,
  241.                                         MPIS_MODENAME,opts[OPT_MODENAME],
  242.                                         MPIS_FORMAT,opts[OPT_FORMAT],
  243.                                         MPIS_PALETTE,opts[OPT_PALETTE],
  244.                                         opts[OPT_COLOURS]?MPIS_COLOURS:TAG_IGNORE,opts[OPT_COLOURS] ? *((ULONG *)opts[OPT_COLOURS]) : 0,
  245.                                         MPIS_12BIT, opts[OPT_12BIT],
  246.                                         MPIS_LINEAR, opts[OPT_LINEAR],
  247.                                         MPIS_GREYMAP, GreyMap,
  248.                                         TAG_END)) {
  249.                         if (FromWB) {
  250.                             es.es_TextFormat = MPImageErrorMessage();
  251.                             EasyRequestArgs(NULL,&es,NULL,NULL);
  252.                         }
  253.                         else {
  254.                             Printf(MPImageErrorMessage());
  255.                             Printf("\n");
  256.                         }
  257.                         resx = RETURN_FAIL;
  258.                     }
  259.                 }
  260.                 FreeMPImage(MPi);
  261.             }
  262.             else {
  263.                 if (FromWB) {
  264.                     es.es_TextFormat = MPImageErrorMessage();
  265.                     EasyRequestArgs(NULL,&es,NULL,NULL);
  266.                 }
  267.                 else {
  268.                     Printf(MPImageErrorMessage());
  269.                     Printf("\n");
  270.                 }
  271.                 resx = RETURN_FAIL;
  272.             }
  273.         }
  274.         else {
  275.             if (opts[OPT_EGS]) {
  276.                 if ((EGSBase = OpenLibrary((char *)"egs.library",0)) &&
  277.                      (EGSGfxBase = OpenLibrary((char *)"egsgfx.library",0)) &&
  278.                     (EGSIntuiBase = OpenLibrary((char *)"egsintui.library", 0))) {
  279.                    screen = NULL;
  280.                     if (MPi=LoadMPImage((UBYTE *)opts[OPT_FILE],screen,MPIF_EGS)) {
  281.                         if (opts[OPT_MINX]) {
  282.                             if (MPi->Width < *((ULONG *)opts[OPT_MINX])) {
  283.                                 newx = *((ULONG *)opts[OPT_MINX]);
  284.                             }
  285.                         }
  286.                         if (opts[OPT_MAXX]) {
  287.                             if (MPi->Width > *((ULONG *)opts[OPT_MAXX])) {
  288.                                 newx = *((ULONG *)opts[OPT_MAXX]);
  289.                             }
  290.                         }
  291.                         if (!opts[OPT_MINX] && !opts[OPT_MAXX]) {
  292.                             if (opts[OPT_X]) {
  293.                                 newx = *((ULONG *)opts[OPT_X]);
  294.                             }
  295.                         }
  296.                         if (opts[OPT_MINY]) {
  297.                             if (MPi->Height < *((ULONG *)opts[OPT_MINY])) {
  298.                                 newy = *((ULONG *)opts[OPT_MINY]);
  299.                             }
  300.                         }
  301.                         if (opts[OPT_MAXY]) {
  302.                             if (MPi->Height > *((ULONG *)opts[OPT_MAXY])) {
  303.                                 newy = *((ULONG *)opts[OPT_MAXY]);
  304.                             }
  305.                         }
  306.                         if (!opts[OPT_MINY] && !opts[OPT_MAXY]) {
  307.                             if (opts[OPT_Y]) {
  308.                                 newy = *((ULONG *)opts[OPT_Y]);
  309.                             }
  310.                         }
  311.                         if (newx || newy) {
  312.                             if (!newx) {
  313.                                 newx = MPi->Width;
  314.                             }
  315.                             if (!newy) {
  316.                                 newy = MPi->Height;
  317.                             }
  318.                             if (!RescaleMPImage(MPi,newx,newy)) {
  319.                                 if (FromWB) {
  320.                                     es.es_TextFormat = MPImageErrorMessage();
  321.                                     EasyRequestArgs(NULL,&es,NULL,NULL);
  322.                                 }
  323.                                 else {
  324.                                     Printf(MPImageErrorMessage());
  325.                                     Printf("\n");
  326.                                 }
  327.                                 resx = RETURN_FAIL;
  328.                             }
  329.                         }
  330.                         if (!resx) {
  331.                             EGS_NewWindow.LeftEdge = 0;
  332.                             EGS_NewWindow.TopEdge = 20;
  333.                             EGS_NewWindow.Width = MPi->Width;
  334.                             EGS_NewWindow.Height = MPi->Height;
  335.                             EGS_NewWindow.MinWidth = 20;
  336.                             EGS_NewWindow.MinHeight = 20;
  337.                             EGS_NewWindow.MaxWidth = MPi->Width;
  338.                             EGS_NewWindow.MaxHeight = MPi->Height;
  339.                             EGS_NewWindow.Screen = NULL;
  340.                             EGS_NewWindow.Bordef.SysGadgets = EI_WINDOWSIZE | EI_WINDOWFRONT | EI_WINDOWFLIP |
  341.                                                                          EI_WINDOWARROWL | EI_WINDOWARROWR | EI_WINDOWARROWU | EI_WINDOWARROWD |
  342.                                                                          EI_WINDOWSCROLLH | EI_WINDOWSCROLLV | EI_WINDOWDRAG |
  343.                                                                          EI_WINDOWCLOSE;
  344.                             EGS_NewWindow.FirstGadgets = NULL;
  345.                             EGS_NewWindow.Title = (char *)opts[OPT_FILE];
  346.                             EGS_NewWindow.Flags = EI_GIMMEZEROZERO | EI_SUPER_BITMAP | EI_WINDOWACTIVE | EI_REPORTMOUSE | EI_QUICKSCROLL | EI_RMBTRAP;
  347.                             EGS_NewWindow.IDCMPFlags = EI_iCLOSEWINDOW;
  348.                             EGS_NewWindow.Port = NULL;
  349.                             EGS_NewWindow.Menu = NULL;
  350.                             EGS_NewWindow.Render = NULL;
  351.                             if (EGS_Win = EI_OpenWindow(&EGS_NewWindow)) {
  352.                                 E_ActivateEGSScreen();
  353.                                 EG_CopyBitMapRastPort(MPi->EGS_BitMap,EGS_Win->RPort,0,0,MPi->Width,MPi->Height,0,0);
  354.                                 done = FALSE;
  355.                                 while    (!done) {
  356.                                     WaitPort(EGS_Win->UserPort);
  357.                                     while (EGSmsg = (struct EI_EIntuiMsg *)GetMsg(EGS_Win->UserPort)) {
  358.                                         switch (EGSmsg->Class) {
  359.                                         case EI_iCLOSEWINDOW:
  360.                                             done = TRUE;
  361.                                             break;
  362.                                         default:
  363.                                             break;
  364.                                         }
  365.                                         ReplyMsg((struct Message *)EGSmsg); 
  366.                                     }
  367.                                 }
  368.                                 EI_CloseWindow(EGS_Win);
  369.                             }
  370.                         }
  371.                         FreeMPImage(MPi);
  372.                     }
  373.                     else {
  374.                         if (FromWB) {
  375.                             es.es_TextFormat = MPImageErrorMessage();
  376.                             EasyRequestArgs(NULL,&es,NULL,NULL);
  377.                         }
  378.                         else {
  379.                             Printf(MPImageErrorMessage());
  380.                             Printf("\n");
  381.                         }
  382.                         resx = RETURN_FAIL;
  383.                     }
  384.                 }
  385.                 if (EGSIntuiBase) {
  386.                     CloseLibrary(EGSIntuiBase);
  387.                 }
  388.                 if (EGSGfxBase) {
  389.                     CloseLibrary(EGSGfxBase);
  390.                 }
  391.                 if (EGSBase) {
  392.                     CloseLibrary(EGSBase);
  393.                 }
  394.             }
  395.             else {
  396.                 if (screen = LockPubScreen((UBYTE *)opts[OPT_SCREEN])) {
  397.                     if (MPi=LoadMPImage((UBYTE *)opts[OPT_FILE],screen,
  398.                                 (opts[OPT_CLONE] ? MPIF_CLONEBITMAP : 0) | 
  399.                                 (opts[OPT_NOREMAP] ? MPIF_NOREMAP : 0))) {
  400.                         if (opts[OPT_MINX]) {
  401.                             if (MPi->Width < *((ULONG *)opts[OPT_MINX])) {
  402.                                 newx = *((ULONG *)opts[OPT_MINX]);
  403.                             }
  404.                         }
  405.                         if (opts[OPT_MAXX]) {
  406.                             if (MPi->Width > *((ULONG *)opts[OPT_MAXX])) {
  407.                                 newx = *((ULONG *)opts[OPT_MAXX]);
  408.                             }
  409.                         }
  410.                         if (!opts[OPT_MINX] && !opts[OPT_MAXX]) {
  411.                             if (opts[OPT_X]) {
  412.                                 newx = *((ULONG *)opts[OPT_X]);
  413.                             }
  414.                         }
  415.                         if (opts[OPT_MINY]) {
  416.                             if (MPi->Height < *((ULONG *)opts[OPT_MINY])) {
  417.                                 newy = *((ULONG *)opts[OPT_MINY]);
  418.                             }
  419.                         }
  420.                         if (opts[OPT_MAXY]) {
  421.                             if (MPi->Height > *((ULONG *)opts[OPT_MAXY])) {
  422.                                 newy = *((ULONG *)opts[OPT_MAXY]);
  423.                             }
  424.                         }
  425.                         if (!opts[OPT_MINY] && !opts[OPT_MAXY]) {
  426.                             if (opts[OPT_Y]) {
  427.                                 newy = *((ULONG *)opts[OPT_Y]);
  428.                             }
  429.                         }
  430.                         if (newx || newy) {
  431.                             if (!newx) {
  432.                                 newx = MPi->Width;
  433.                             }
  434.                             if (!newy) {
  435.                                 newy = MPi->Height;
  436.                             }
  437.                             if (!RescaleMPImage(MPi,newx,newy)) {
  438.                                 if (FromWB) {
  439.                                     es.es_TextFormat = MPImageErrorMessage();
  440.                                     EasyRequestArgs(NULL,&es,NULL,NULL);
  441.                                 }
  442.                                 else {
  443.                                     Printf(MPImageErrorMessage());
  444.                                     Printf("\n");
  445.                                 }
  446.                                 resx = RETURN_FAIL;
  447.                             }
  448.                         }
  449.                         if (!resx) {
  450.                             if (win = OpenWindowTags(NULL,
  451.                                                         WA_CloseGadget, TRUE,
  452.                                                         WA_PubScreen, screen,
  453.                                                         WA_SuperBitMap, MPi->BitMap,
  454.                                                         WA_IDCMP, IDCMP_CLOSEWINDOW,
  455.                                                         WA_InnerWidth, MPi->Width,
  456.                                                         WA_InnerHeight, MPi->Height,
  457.                                                         WA_Title, opts[OPT_FILE],
  458.                                                         WA_DragBar, TRUE,
  459.                                                         WA_NoCareRefresh, TRUE,
  460.                                                         WA_AutoAdjust, TRUE,
  461.                                                         WA_GimmeZeroZero,TRUE,
  462.                                                         TAG_END)) {
  463.                                 done = FALSE;
  464.                                 while    (!done) {
  465.                                     WaitPort(win->UserPort);
  466.                                      while (msg = (struct IntuiMessage *)GetMsg(win->UserPort)) {
  467.                                          switch (msg->Class) {
  468.                                          case IDCMP_CLOSEWINDOW:
  469.                                              // Close window
  470.                                             done = TRUE;
  471.                                              break;
  472.                                          default:
  473.                                              // unknown message
  474.                                              break;
  475.                                              }
  476.                                         ReplyMsg((struct Message *)msg);
  477.                                      }
  478.                                 }    
  479.                                 CloseWindow(win);
  480.                             }
  481.                         }
  482.                         FreeMPImage(MPi);
  483.                     }
  484.                     else {
  485.                         if (FromWB) {
  486.                             es.es_TextFormat = MPImageErrorMessage();
  487.                             EasyRequestArgs(NULL,&es,NULL,NULL);
  488.                         }
  489.                         else {
  490.                             Printf(MPImageErrorMessage());
  491.                             Printf("\n");
  492.                         }
  493.                         resx = RETURN_FAIL;
  494.                     }
  495.                     UnlockPubScreen(NULL,screen);
  496.                 }
  497.                 else {
  498.                     if (FromWB) {
  499.                         es.es_TextFormat = GetMessage(MSG_SCREEN);
  500.                         EasyRequest(NULL,&es,NULL,(UBYTE *)opts[OPT_SCREEN]);
  501.                     }
  502.                     else {
  503.                         Printf(GetMessage(MSG_SCREEN),(UBYTE *)opts[OPT_SCREEN]);
  504.                         Printf("\n");
  505.                     }
  506.                 }
  507.             }
  508.         }
  509.         CloseLibrary(MPImageBase);
  510.     }
  511.     else {
  512.         if (FromWB) {
  513.             es.es_TextFormat = GetMessage(MSG_LIBRARY);
  514.             EasyRequestArgs(NULL,&es,NULL,NULL);
  515.         }
  516.         else {
  517.             Printf(GetMessage(MSG_LIBRARY));
  518.             Printf("\n");
  519.         }
  520.         resx = RETURN_FAIL;
  521.     }
  522.     if (rdargs) {
  523.         FreeArgs(rdargs);
  524.     }
  525.     CloseCatalog(Catalog);
  526.     return resx;
  527. }
  528.